<template>
  <el-container>
    <el-main>
      <div style="width: 100%;display: flex;align-items: flex-end;border-bottom: 1px #eee solid;margin-bottom: 20px">
        <span style="font-size: 18px;color:#409EFF;margin: 10px 0;">基本信息</span>
      </div>
      <el-form ref="parkingForm" :model="parkingForm" :rules="rules"  label-width="100px">
            <el-form-item label="停车场名称" prop="name">
              <el-input v-model="parkingForm.name" style="width:300px"></el-input>
            </el-form-item>
             <el-form-item label="免费时长" >
            <el-select
        v-model="parkingForm.freeMinutes"
        placeholder="请选择"
        style="width: 300px"
      >
        <el-option
          v-for="item in reachDateOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
             </el-form-item>
          <el-form-item label="车场编号" prop="parkKey">
            <el-input type="text" v-model="parkingForm.parkKey" style="width:300px"></el-input>
          </el-form-item>
          <el-form-item label="appId" prop="appId">
            <el-input type="text" v-model="parkingForm.appId" style="width:300px"></el-input>
          </el-form-item>
          <el-form-item label="appSecret" prop="appSecret">
            <el-input type="text" v-model="parkingForm.appSecret" style="width:300px"></el-input>
          </el-form-item>
          <el-form-item label="停场类型">
           <el-select v-model="parkingForm.platformName" value-key="value" placeholder="请选择" style="width:300px" @change="platformNamechange">
            <el-option  v-for="item in platformNamelist" :key="item.value" :label="item.label" :value="item" >
              
            </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="支付类型">
           <el-select v-model="parkingForm.paymentPluginName" value-key="value" placeholder="请选择" style="width:300px" @change="paymentPluginchange">
            <el-option
             v-for="item in paymentPlugin" :key="item.value" :label="item.label" :value="item">
            </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="增加出口">
            <el-row style="display: flex;position: relative;">
               <span class="el-icon-plus" style="position: absolute;color: #409EFF;left: -45px;top: 74px;" @click="changclick"/>
            <el-col :span="12">
               <el-table :data="parkingForm.exitList" border stripe style="width: 100%;" >
              <el-table-column label="出口编号(车道控制机号)" width="220" >
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.ctrlNo" />
                    </template>
              </el-table-column>

                  <el-table-column
                    label="操作"
                    min-width="120"
                    align="center"
                  >
                    <template slot-scope="scope">
                    <div>
                    <!-- <el-tooltip class="item" effect="dark" content="编辑" placement="top-start">
                        <a>
                    <i style="color: #409EFF" class="el-icon-edit"></i>
                       </a>
                     </el-tooltip> -->
              <el-tooltip  class="item" effect="dark" content="删除" placement="top-start">
                <a style="margin-left: 10px" @click="dellist(scope.$index)">
                  <i style="color: #F56C6C" class="el-icon-delete"></i>
                </a>
              </el-tooltip>
            </div>
                    </template>
                  </el-table-column>
                </el-table>
            </el-col>
              
            </el-row>
          </el-form-item>
        <el-form-item class="addBotton">
          <el-button type="primary" :loading="loading" @click="saveSysPost('parkingForm')">立即创建</el-button>
        </el-form-item>
    
      </el-form>
    </el-main>
  </el-container>
</template>

<script>
  import {save} from '@/api/parking'
  import utils from '../../utils/utils.js'
  import { EventBus } from '@/api/eventBus'
  export default {
    name:'parking-add',
    data() {
      return {
        nowDate:null,
        paymentPlugin:[{
          label:'微信支付',
          value:'weixinPayPlugin',
        }],
        platformNamelist:[{
          label:'智慧停车场',
          value:'szymzh',
        }],
         reachDateOptions: [
        {
          value: 15,
          label: "15分钟",
        },
        {
          value: 30,
          label: "30分钟",
        },
        {
          value: 45,
          label: "45分钟",
        },
        {
          value: 60,
          label: "1小时",
        },
        {
          value: 120,
          label: "2小时",
        },
        {
          value: 180,
          label: "3小时",
        },
        {
          value: 240,
          label: "4小时",
        },
        {
          value: 300,
          label: "5小时",
        },
        {
          value: 360,
          label: "6小时",
        },
        {
          value: 420,
          label: "7小时",
        },
        {
          value: 480,
          label: "8小时",
        },
        {
          value: 540,
          label: "9小时",
        },
        {
          value: 600,
          label: "10小时",
        },
        {
          value: 660,
          label: "11小时",
        },
        {
          value: 720,
          label: "12小时",
        },
        {
          value: 780,
          label: "13小时",
        },
        {
          value: 840,
          label: "14小时",
        },
        {
          value: 900,
          label: "15小时",
        },
        {
          value: 960,
          label: "16小时",
        },
        {
          value: 1020,
          label: "17小时",
        },
        {
          value: 1080,
          label: "18小时",
        },
        {
          value: 1140,
          label: "19小时",
        },
        {
          value: 1200,
          label: "20小时",
        },
        {
          value: 1260,
          label: "21小时",
        },
        {
          value: 1320,
          label: "22小时",
        },
        {
          value: 1380,
          label: "23小时",
        },
        {
          value: 1440,
          label: "24小时",
        },
        {
            value: 2880,
          label: "两天",
        },
        {
           value: 4320,
          label: "三天",
        }
      ],
        parkingForm: {
          createDate:'',
          paymentPluginName:null,
          paymentPluginId:null,
          name: '',
          parkKey:'',
          platform:null,
          platformName:null,
          appSecret:'',
          appId:'',
          exitList:[{ctrlNo:''}],
        },
        loading: false,
        rules: {
          name: [
            { required: true, message: '请输入组织名称', trigger: 'blur' },
            { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
          ],
          parkKey: [
            { required: true, message: '请输入车场编号', trigger: 'blur' },
          ],
          appId: [
            { required: true, message: '请输入appId', trigger: 'blur' },
          ],
          appSecret: [
            { required: true, message: '请输入appSecret', trigger: 'blur' },
          ],
        },
        inputType:false
      };
    },
    methods: {
      dellist(data){
      this.parkingForm.exitList.splice(data,1)

      },
      platformNamechange(val){
        this.parkingForm.platformName=val.label
        this.parkingForm.platform=val.value
      },
      paymentPluginchange(val){
        this.parkingForm.paymentPluginName=val.label
        this.parkingForm.paymentPluginId=val.value
      },
      changclick(){
         const nweobj={ctrlNo:''}
         this.parkingForm.exitList.push(nweobj)
      },
      saveSysPost(parkingForm) {
        var _this = this
        this.$refs[parkingForm].validate((valid) => {
          if (valid) { // 校验表单
            _this.loading = true
            save(_this.parkingForm).then(response => {
              console.log(response);
              _this.loading = false;
              _this.$message({
                message: response.content,
                offset: 120,
                center: true
              });
              EventBus.$emit('parking-add', response.data)
              _this.$store.dispatch('tagsView/delView', _this.$route).then(({ visitedViews }) => {
                _this.$router.push({
                  path: '/parking/list'
                })
              })// 关闭当前tab回到列表
            }).catch(error => {
              _this.loading = false;
              console.log('error!!')
            });
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    },
  }
</script>

<style scoped>
  .el-headerBox {
    height: 50px !important;
    border-bottom: 1px solid #eee !important;
    line-height: 50px !important;
  }
  .addBotton{
     margin-top: 100px;
  }
  .el-headerTitle{
    font-size: 20px;
    color: #409EFF;
  }
</style>
